<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 引入vue2的js文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.9/vue.js"></script>
    <script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
  </head>
  <body>
    <div id="app">
      <!-- | 管道符 -->
      <p>date is {{ date | formatTime }}</p>
      <p>date is {{ date1 | formatTime2('YYYY-MM-DD')}}</p>
    </div>

    <script>
      new Vue({
        el: '#app',
        data: {
          date: new Date(),
          date1: new Date() - 0
        },
        filters: {
          formatTime(value) {
            // 过滤器 & 计算属性都要有返回值
            return dayjs(value).format('YYYY-MM-DD HH:mm:ss')
          },
          formatTime2(value, formatStr = 'YYYY-MM-DD HH:mm:ss') {
            return dayjs(value).format(formatStr)
          }
        }
      })
    </script>
  </body>
</html>
